package com.java110.mall.cart.bmo.storeOrderDiscount.impl;

import com.java110.mall.cart.bmo.storeOrderDiscount.IGetStoreOrderDiscountBMO;
import com.java110.dto.storeOrder.StoreOrderDiscountDto;
import com.java110.intf.cart.IStoreOrderDiscountInnerServiceSMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("getStoreOrderDiscountBMOImpl")
public class GetStoreOrderDiscountBMOImpl implements IGetStoreOrderDiscountBMO {

    @Autowired
    private IStoreOrderDiscountInnerServiceSMO storeOrderDiscountInnerServiceSMOImpl;

    /**
     *
     *
     * @param  storeOrderDiscountDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(StoreOrderDiscountDto storeOrderDiscountDto) {


        int count = storeOrderDiscountInnerServiceSMOImpl.queryStoreOrderDiscountsCount(storeOrderDiscountDto);

        List<StoreOrderDiscountDto> storeOrderDiscountDtos = null;
        if (count > 0) {
            storeOrderDiscountDtos = storeOrderDiscountInnerServiceSMOImpl.queryStoreOrderDiscounts(storeOrderDiscountDto);
        } else {
            storeOrderDiscountDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) storeOrderDiscountDto.getRow()), count, storeOrderDiscountDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
